package com.cjl.dental_clinic.controller;

import com.cjl.dental_clinic.Req.LoginReq;
import com.cjl.dental_clinic.base.BaseController;
import com.cjl.dental_clinic.base.ResVo;
import com.cjl.dental_clinic.entity.User;
import com.cjl.dental_clinic.Req.UserReq;
import com.cjl.dental_clinic.service.UserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lbw
 */
@RestController
@RequestMapping("/cjl/user")
public class UserController extends BaseController<User, UserService> {
    public UserController(UserService baseService) {
        super(baseService);
    }
    /**
     * 用户登录
     */
    @PostMapping("/login")
    public ResVo loginUser(LoginReq loginReq){
        return baseService.Login(loginReq);
    }
    /**
     * 用户注册
     */
    @PostMapping("/register")
    public ResVo<String> registerUser(LoginReq loginReq){
        return baseService.register(loginReq);
    }

    /**
     * 用户列表
     * @return
     */
    @PostMapping("list")
    public ResVo<List<UserReq>> list() {
        return ResVo.ok(baseService.selectNoPassword());
    }

    /**
     * 删除用户
     */
    @PostMapping("del")
    public ResVo<Boolean> delUser(Integer id) {
        return ResVo.ok(baseService.removeById(id));
    }
    /**
     * 修改用户状态
     */
    @PostMapping("status")
    public ResVo<Boolean> userStatus(Integer id){
        return ResVo.ok(baseService.userStatus(id));
    }

    /**
     * 修改密码
     */
    @PostMapping("modify")
    public ResVo<String> modify(LoginReq user){
        if (baseService.modify(user)){
            return ResVo.ok("修改成功");
        }
        return ResVo.error("修改失败");
    }

}
